home *** CD-ROM | disk | FTP | other *** search
/ Macwelt 4 / Macwelt DVD 4.cdr / Entwickler / Mac-OS / oxygen / oxygen.app / Contents / Resources / Java / jh.jar / javax / help / HelpSet$HelpSetParser.class (.txt) < prev    next >
Encoding:
Java Class File  |  2002-06-24  |  7.4 KB  |  353 lines

  1. package javax.help;
  2.  
  3. import com.sun.java.help.impl.LangElement;
  4. import com.sun.java.help.impl.Parser;
  5. import com.sun.java.help.impl.ParserEvent;
  6. import com.sun.java.help.impl.ParserListener;
  7. import com.sun.java.help.impl.Tag;
  8. import com.sun.java.help.impl.TagProperties;
  9. import java.io.IOException;
  10. import java.io.Reader;
  11. import java.util.Hashtable;
  12. import java.util.Locale;
  13. import java.util.Stack;
  14.  
  15. class HelpSet$HelpSetParser implements ParserListener {
  16.    private Stack tagStack;
  17.    private Locale defaultLocale;
  18.    private Locale lastLocale;
  19.    private HelpSet myHS;
  20.    private Locale myHSLocale;
  21.    private HelpSetFactory factory;
  22.    private String viewName;
  23.    private String viewLabel;
  24.    private String viewType;
  25.    private String viewEngine;
  26.    private String viewImage;
  27.    private String viewData;
  28.    private Hashtable htData;
  29.  
  30.    HelpSet$HelpSetParser(HelpSetFactory var1) {
  31.       this.factory = var1;
  32.    }
  33.  
  34.    synchronized void parseInto(Reader var1, HelpSet var2) throws IOException {
  35.       this.tagStack = new Stack();
  36.       this.defaultLocale = var2.getLocale();
  37.       this.lastLocale = this.defaultLocale;
  38.       this.myHS = var2;
  39.       this.myHSLocale = var2.getLocale();
  40.       Parser var3 = new Parser(var1);
  41.       var3.addParserListener(this);
  42.       var3.parse();
  43.    }
  44.  
  45.    public void tagFound(ParserEvent var1) {
  46.       HelpSet.access$000("tagFound");
  47.       Locale var2 = null;
  48.       Tag var4 = var1.getTag();
  49.       String var5 = var4.name;
  50.       TagProperties var6 = var4.atts;
  51.       Hashtable var7 = var6 == null ? null : var6.getHashtable();
  52.       if (var6 != null) {
  53.          String var8 = var6.getProperty("xml:lang");
  54.          var2 = HelpUtilities.localeFromLang(var8);
  55.       }
  56.  
  57.       if (var2 == null) {
  58.          var2 = this.lastLocale;
  59.       }
  60.  
  61.       if (var5.equals("helpset")) {
  62.          if (var4.isEnd) {
  63.             this.removeTag(var4);
  64.          } else {
  65.             if (!var2.equals(this.defaultLocale) && !var2.equals(this.myHSLocale) && var2 != null) {
  66.                HelpSet.access$200(this.myHS, var2);
  67.                this.defaultLocale = var2;
  68.             }
  69.  
  70.             if (var6 != null) {
  71.                String var10 = var6.getProperty("version");
  72.                if (var10 != null && var10.compareTo("1.0") != 0) {
  73.                   this.parsingError("helpset.unknownVersion", var10);
  74.                }
  75.             }
  76.  
  77.             this.addTag(var4, var2);
  78.          }
  79.  
  80.       } else {
  81.          if (this.tagStack.empty()) {
  82.             this.parsingError("helpset.wrongTopLevel", var5);
  83.          }
  84.  
  85.          LangElement var3 = (LangElement)this.tagStack.peek();
  86.          String var9 = var3.getTag().name;
  87.          if (var5.equals("title")) {
  88.             if (var4.isEnd) {
  89.                this.removeTag(var4);
  90.             } else {
  91.                if (!var9.equals("helpset")) {
  92.                   this.wrongParent(var5, var9);
  93.                }
  94.  
  95.                if (!var2.equals(this.defaultLocale) && !var2.equals(this.myHSLocale)) {
  96.                   this.wrongLocale(var2, this.defaultLocale, this.myHSLocale);
  97.                }
  98.  
  99.                this.addTag(var4, var2);
  100.             }
  101.          } else if (var5.equals("homeID")) {
  102.             if (var4.isEnd) {
  103.                this.removeTag(var4);
  104.             } else {
  105.                if (!var9.equals("maps")) {
  106.                   this.wrongParent(var5, var9);
  107.                }
  108.  
  109.                this.addTag(var4, var2);
  110.             }
  111.          } else if (var5.equals("mapref")) {
  112.             if (var4.isEnd && !var4.isEmpty) {
  113.                this.removeTag(var4);
  114.             } else {
  115.                if (!var9.equals("maps")) {
  116.                   this.wrongParent(var5, var9);
  117.                }
  118.  
  119.                if (!var4.isEmpty) {
  120.                   this.addTag(var4, var2);
  121.                }
  122.  
  123.                this.factory.processMapRef(this.myHS, var7);
  124.             }
  125.          } else if (var5.equals("data")) {
  126.             if (var4.isEnd) {
  127.                this.removeTag(var4);
  128.             } else {
  129.                if (!var9.equals("view")) {
  130.                   this.wrongParent(var5, var9);
  131.                } else {
  132.                   this.addTag(var4, var2);
  133.                }
  134.  
  135.                this.htData = var7;
  136.             }
  137.          } else if (!var5.equals("name") && !var5.equals("type") && !var5.equals("image")) {
  138.             if (var5.equals("label")) {
  139.                if (var4.isEnd) {
  140.                   this.removeTag(var4);
  141.                } else if (!var9.equals("view")) {
  142.                   this.wrongParent(var5, var9);
  143.                } else {
  144.                   if (!var2.equals(this.defaultLocale) && !var2.equals(this.myHSLocale)) {
  145.                      this.wrongLocale(var2, this.defaultLocale, this.myHSLocale);
  146.                   }
  147.  
  148.                   this.addTag(var4, var2);
  149.                }
  150.             } else if (var5.equals("view")) {
  151.                if (var4.isEnd) {
  152.                   this.removeTag(var4);
  153.                   if (this.viewImage != null) {
  154.                      if (this.htData == null) {
  155.                         this.htData = new Hashtable();
  156.                      }
  157.  
  158.                      this.htData.put("imageID", this.viewImage);
  159.                   }
  160.  
  161.                   this.factory.processView(this.myHS, this.viewName, this.viewLabel, this.viewType, var7, this.viewData, this.htData, var2);
  162.                   this.viewName = null;
  163.                   this.viewLabel = null;
  164.                   this.viewType = null;
  165.                   this.viewImage = null;
  166.                   this.viewData = null;
  167.                   this.htData = null;
  168.                } else if (!var9.equals("helpset")) {
  169.                   this.wrongParent(var5, var9);
  170.                } else {
  171.                   this.addTag(var4, var2);
  172.                }
  173.             } else if (var5.equals("maps")) {
  174.                if (var4.isEnd) {
  175.                   this.removeTag(var4);
  176.                } else if (!var9.equals("helpset")) {
  177.                   this.wrongParent(var5, var9);
  178.                } else {
  179.                   this.addTag(var4, var2);
  180.                }
  181.             } else if (var5.equals("subhelpset")) {
  182.                if (var4.isEnd && !var4.isEmpty) {
  183.                   this.removeTag(var4);
  184.                } else {
  185.                   if (!var4.isEmpty) {
  186.                      this.addTag(var4, var2);
  187.                   }
  188.  
  189.                   this.factory.processSubHelpSet(this.myHS, var7);
  190.                }
  191.             }
  192.          } else if (var4.isEnd) {
  193.             this.removeTag(var4);
  194.          } else if (!var9.equals("view")) {
  195.             this.wrongParent(var5, var9);
  196.          } else {
  197.             this.addTag(var4, var2);
  198.          }
  199.  
  200.       }
  201.    }
  202.  
  203.    public void piFound(ParserEvent var1) {
  204.       this.factory.processPI(this.myHS, var1.getTarget(), var1.getData());
  205.    }
  206.  
  207.    public void doctypeFound(ParserEvent var1) {
  208.       this.factory.processDOCTYPE(var1.getRoot(), var1.getPublicId(), var1.getSystemId());
  209.    }
  210.  
  211.    private void checkNull(String var1, String var2) {
  212.       if (!var2.equals("")) {
  213.          this.parsingError("helpset.wrongText", var1, var2);
  214.       }
  215.  
  216.    }
  217.  
  218.    public void textFound(ParserEvent var1) {
  219.       HelpSet.access$000("textFound: ");
  220.       HelpSet.access$000("  text: " + var1.getText());
  221.       if (!this.tagStack.empty()) {
  222.          LangElement var2 = (LangElement)this.tagStack.peek();
  223.          Tag var3 = var2.getTag();
  224.          TagProperties var4 = var3.atts;
  225.          if (var4 == null) {
  226.             Object var10000 = null;
  227.          } else {
  228.             var4.getHashtable();
  229.          }
  230.  
  231.          String var6 = var1.getText().trim();
  232.          String var7 = var3.name;
  233.          if (var7.equals("helpset")) {
  234.             this.checkNull("helpset", var6);
  235.          } else {
  236.             int var8 = this.tagStack.size();
  237.             String var9 = "";
  238.             if (var8 >= 2) {
  239.                var2 = (LangElement)this.tagStack.elementAt(var8 - 2);
  240.                var9 = var2.getTag().name;
  241.             }
  242.  
  243.             if (var7.equals("title")) {
  244.                this.factory.processTitle(this.myHS, var6);
  245.             } else if (var7.equals("homeID")) {
  246.                this.factory.processHomeID(this.myHS, var6);
  247.             } else if (var7.equals("mapref")) {
  248.                this.checkNull("mapref", var6);
  249.             } else if (var7.equals("subhelpset")) {
  250.                this.checkNull("subhelpset", var6);
  251.             } else if (var7.equals("data")) {
  252.                this.viewData = var6.trim();
  253.             } else if (var7.equals("label")) {
  254.                this.viewLabel = var6.trim();
  255.             } else if (var7.equals("name")) {
  256.                this.viewName = var6.trim();
  257.             } else if (var7.equals("type")) {
  258.                this.viewType = var6.trim();
  259.             } else if (var7.equals("image")) {
  260.                this.viewImage = var6.trim();
  261.             } else if (var7.equals("view")) {
  262.                this.checkNull("view", var6);
  263.             } else if (var7.equals("maps")) {
  264.                this.checkNull("maps", var6);
  265.             }
  266.  
  267.          }
  268.       }
  269.    }
  270.  
  271.    public void errorFound(ParserEvent var1) {
  272.    }
  273.  
  274.    public void commentFound(ParserEvent var1) {
  275.    }
  276.  
  277.    protected void addTag(Tag var1, Locale var2) {
  278.       LangElement var3 = new LangElement(var1, var2);
  279.       this.tagStack.push(var3);
  280.       if (this.lastLocale == null) {
  281.          this.lastLocale = var2;
  282.       } else if (var2 == null) {
  283.          this.lastLocale = var2;
  284.       } else {
  285.          if (!this.lastLocale.equals(var2)) {
  286.             this.lastLocale = var2;
  287.          }
  288.  
  289.       }
  290.    }
  291.  
  292.    protected void removeTag(Tag var1) {
  293.       String var3 = var1.name;
  294.       Object var4 = null;
  295.  
  296.       LangElement var2;
  297.       do {
  298.          if (this.tagStack.empty()) {
  299.             this.unbalanced(var3);
  300.          }
  301.  
  302.          var2 = (LangElement)this.tagStack.pop();
  303.       } while(!var2.getTag().name.equals(var3));
  304.  
  305.       Locale var6;
  306.       if (this.tagStack.empty()) {
  307.          var6 = this.defaultLocale;
  308.       } else {
  309.          var2 = (LangElement)this.tagStack.peek();
  310.          var6 = var2.getLocale();
  311.       }
  312.  
  313.       if (this.lastLocale == null) {
  314.          this.lastLocale = var6;
  315.       } else if (var6 == null) {
  316.          this.lastLocale = var6;
  317.       } else {
  318.          if (!this.lastLocale.equals(var6)) {
  319.             this.lastLocale = var6;
  320.          }
  321.  
  322.       }
  323.    }
  324.  
  325.    private void parsingError(String var1) {
  326.       String var2 = HelpUtilities.getText(var1);
  327.       this.factory.reportMessage(var2, false);
  328.    }
  329.  
  330.    private void parsingError(String var1, String var2) {
  331.       String var3 = HelpUtilities.getText(var1, var2);
  332.       this.factory.reportMessage(var3, false);
  333.    }
  334.  
  335.    private void parsingError(String var1, String var2, String var3) {
  336.       String var4 = HelpUtilities.getText(var1, var2, var3);
  337.       this.factory.reportMessage(var4, false);
  338.    }
  339.  
  340.    private void wrongParent(String var1, String var2) {
  341.       this.parsingError("helpset.wrongParent", var1, var2);
  342.    }
  343.  
  344.    private void unbalanced(String var1) {
  345.       this.parsingError("helpset.unbalanced", var1);
  346.    }
  347.  
  348.    private void wrongLocale(Locale var1, Locale var2, Locale var3) {
  349.       String var4 = HelpUtilities.getText("helpset.wrongLocale", var1.toString(), var2.toString(), var3.toString());
  350.       this.factory.reportMessage(var4, true);
  351.    }
  352. }
  353.